package com.lzx.applib.data;

import android.text.TextUtils;

import org.w3c.dom.Text;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Lzx on 16/09/12 0012.
 */
public class AppUrls implements IXmlParser {

    private String releaseBase;
    private String debugBase;

    private Map<String, AppUrl> appUrlMap = new HashMap<>();

    @Override
    public void parse(XmlPullParser parser) {
        releaseBase = parser.getAttributeValue(null, "release");
        debugBase = parser.getAttributeValue(null, "debug");

        try {
            while (parser.getEventType() != XmlPullParser.END_DOCUMENT) {
                parser.nextTag();
                String tag = parser.getName();

                if (parser.getEventType() == XmlPullParser.START_TAG && TextUtils.equals(tag, "url")) {
                    AppUrl appUrl = new AppUrl();
                    appUrl.parse(parser);

                    appUrlMap.put(appUrl.name, appUrl);
                }

                if (TextUtils.equals(tag, "app")) {
                    return;
                }
            }
        } catch (XmlPullParserException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
